package xiangmu.schoolpaper.controller.bingo.system;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xiangmu.schoolpaper.pojo.VO.*;
import xiangmu.schoolpaper.result.Result;
import xiangmu.schoolpaper.service.system.*;
import java.util.List;

@RestController
@RequestMapping("/system/sa")
@Slf4j
@Tag(name = "管理员端——6统计分析")
public class SystemStatisticAnalysisController {
    @Autowired
    private SystemStatisticAnalysisService systemStatisticAnalysisService;

    @Autowired
    private StatisticAnalysisService statisticAnalysisService;

    @Autowired
    private PredictionKeywordsService predictionKeywordsService;

    /*
        准备条件
     */
    @Operation(summary = "1获取所有毕业年份")
    @GetMapping("/get-all-years")
    public Result<List<Integer>> getAllCompletionYearsSA(){
        log.info("获取所有毕业年份");
        List<Integer> list = predictionKeywordsService.getAllCompletionYears();
        return Result.success(list);
    }

    @Operation(summary = "2获取所有专业名称")
    @GetMapping("/get-all-majors")
    public Result<List<String>> getAllMajorsSA(){
        log.info("获取所有专业名称");
        List<String> list = predictionKeywordsService.getAllMajors();
        return Result.success(list);
    }

    @Operation(summary = "3获取所有老师工号和姓名")
    @GetMapping("/get-all-teachers")
    public Result<List<SystemTeacherInfoVO>> getAllTeachersSA(){
        log.info("获取所有指导教师的工号和姓名");
        List<SystemTeacherInfoVO> list = systemStatisticAnalysisService.getAllTeachers();
        return Result.success(list);
    }

    @Operation(summary = "4某年份下所有专业")
    @GetMapping("/get-all-majors-by-year")
    public Result<List<String>> getAllMajorsByYearSA(@RequestParam Integer year){
        log.info("4某年份下所有专业");
        List<String> majors = systemStatisticAnalysisService.getAllMajorsByYear(year);
        if(majors == null){
            return Result.error("该年份下没有专业");
        }
        return Result.success(majors);
    }

    @Operation(summary = "5某年份下所有老师")
    @GetMapping("/get-all-teachers-by-year")
    public Result<List<SystemTeacherInfoVO>> getAllTeachersByYearSA(@RequestParam Integer year){
        log.info("4某年份下所有老师");
        List<SystemTeacherInfoVO> teachers = systemStatisticAnalysisService.getAllTeachersByYear(year);
        if(teachers == null){
            return Result.error("该年份下没有指导老师");
        }
        return Result.success(teachers);
    }

    @Operation(summary = "6某专业下所有年份")
    @GetMapping("/get-all-years-by-major")
    public Result<List<String>> getAllYearsByMajorSA(@RequestParam String major) {
        log.info("某专业下所有年份");
        List<String> years = systemStatisticAnalysisService.getAllYearsByMajor(major);
        if(years==null){
            return Result.error("该专业没有对应年份");
        }
        return Result.success(years);
    }

    @Operation(summary = "7某老师下所有年份")
    @GetMapping("/get-all-years-by-teacher")
    public Result<List<String>> getAllYearsByTeacherSA(@RequestParam String teacherAccount) {
        log.info("某老师下所有年份");
        List<String> years = systemStatisticAnalysisService.getAllYearsByTeacherAccount(teacherAccount);
        if(years==null){
            return Result.error("该指导教师没有对应年份");
        }
        return Result.success(years);
    }
    /*
        111年份单选-专业单选
     */
//    111-1概览情况
    @Operation(summary = "8年份单选-专业单选_概览")
    @GetMapping("/one-year-one-major-view")
    public Result<SystemSA111viewVO> oneYearOneMajorViewSA(
            @RequestParam Integer graduationYear,
            @RequestParam String majorName
    ) {
        log.info("111年份单选-专业单选_概览");
        SystemSA111viewVO vo = statisticAnalysisService.oneYearOneMajorView(graduationYear, majorName);
        return Result.success(vo);
    }
//    111-2图表区域
    @Operation(summary = "9年份单选-专业单选_图表")
    @GetMapping("/one-year-one-major-chart")
    public Result<SystemSA111ChartVO> oneYearOneMajorChartSA(
            @RequestParam Integer graduationYear,
            @RequestParam String majorName
    ) {
        log.info("111年份单选-专业单选_图表");
        SystemSA111ChartVO vo = statisticAnalysisService.oneYearOneMajorChart(graduationYear, majorName);
        return Result.success(vo);
    }

    /*
        112年份单选-专业多选
     */
//    112-1概览情况
    @Operation(summary = "10年份单选-专业多选_概览")
    @GetMapping("/one-year-multi-major-view")
    public Result<SystemSA112ViewVO> oneYearMultiMajor(
            @RequestParam Integer graduationYear,
            @RequestParam String majorNames
    ){
//        eg.majorNames：
//        前端拼接的字符串为 数据科学与大数据技术（本）,计算机科学与技术（本）,软件工程（本）
//        后端接收的结果也为 数据科学与大数据技术（本）,计算机科学与技术（本）,软件工程（本）
        log.info("112年份单选-专业多选_概览");
        SystemSA112ViewVO vo = statisticAnalysisService.oneYearMultiMajorView(graduationYear, majorNames);
        if(vo == null){
            return Result.error("符合条件的数据为空，请重新选择查询条件");
        }
        return Result.success(vo);
    }
//    112-2图表区域
    @Operation(summary = "11年份单选-专业多选_图表")
    @GetMapping("/one-year-multi-major-chart")
    public Result<SystemSA112ChartVO> oneYearMultiMajorChart(
            @RequestParam Integer graduationYear,
            @RequestParam String majorNames
    ){
        log.info("112年份单选-专业多选_图表");
        SystemSA112ChartVO vo = statisticAnalysisService.oneYearMultiMajorChart(graduationYear, majorNames);
        if(vo == null){
            return Result.error("符合条件的数据为空，请重新选择查询条件");
        }
        return Result.success(vo);
    }

    /*
        121年份单选，老师单选
     */
//    121-1概览情况
    @Operation(summary = "12年份单选-老师单选_概览")
    @GetMapping("/one-year-one-teacher-view")
    public Result<SystemSA121viewVO> oneYearOneTeacherViewSA(
            @RequestParam Integer graduationYear,
            @RequestParam String teacherAccount
    ) {
        log.info("112年份单选-老师单选_概览");
        System.out.println(teacherAccount);
        SystemSA121viewVO vo = statisticAnalysisService.oneYearOneTeacherView(graduationYear, teacherAccount);
        return Result.success(vo);
    }

//    121-2图表区域
    @Operation(summary = "13年份单选-老师单选_图表")
    @GetMapping("/one-year-one-teacher-chart")
    public Result<SystemSA121ChartVO> oneYearOneTeacherChartSA(
            @RequestParam Integer graduationYear,
            @RequestParam String teacherAccount
    ) {
        log.info("121年份单选-老师单选_图表");
        SystemSA121ChartVO vo = statisticAnalysisService.oneYearOneTeacherChart(graduationYear, teacherAccount);
        return Result.success(vo);
    }

    /*
        122 年份单选-老师多选
     */
//    122-1概览情况
    @Operation(summary = "14年份单选-老师多选_概览")
    @GetMapping("/one-year-multi-teacher-view")
    public Result<SystemSA122ViewVO> oneYearMultiTeacherViewSA(@RequestParam Integer graduationYear,@RequestParam String teacherAccounts){
        log.info("122年份单选-老师多选_概览");
        SystemSA122ViewVO vo = statisticAnalysisService.oneYearMultiTeacherView(graduationYear, teacherAccounts);
        if(vo.getPassCount() ==0 || vo.getTeacherCount()==0){
            return Result.error("符合条件的数据为空，请重新选择查询条件");
        }
        return Result.success(vo);
    }
//    122-2图表区域
    @Operation(summary = "15年份单选-老师多选_图表")
    @GetMapping("/one-year-multi-teacher-chart")
    public Result<SystemSA122ChartVO> oneYearMultiTeacherChartSA(@RequestParam Integer graduationYear,@RequestParam String teacherAccounts){
        log.info("122年份单选-老师多选_图表");
        SystemSA122ChartVO vo =statisticAnalysisService.oneYearMultiTeacherChart(graduationYear, teacherAccounts);
        return Result.success(vo);
    }
    
     /*
        22 年份单选-老师多选
     */
//    22-1概览情况
     @Operation(summary = "16专业单选-年份多选_概览")
     @GetMapping("/one-major-multi-year-view")
     public Result<SystemSA22ViewVO> oneMajorMultiYearViewSA(@RequestParam String majorName,@RequestParam String graduationYears){
         log.info("22专业单选-年份多选_概览");
         SystemSA22ViewVO vo = statisticAnalysisService.oneMajorMultiYearView(majorName, graduationYears);
         if(vo.getPassCount()==0|| vo.getYearCount()==0){
             return Result.error("符合条件的数据为空，请重新选择查询条件");
         }
         return Result.success(vo);
     }
//    22-2图表区域
    @Operation(summary = "17专业单选-年份多选_图表")
    @GetMapping("/one-major-multi-year-chart")
    public Result<SystemSA22ChartVO> oneMajorMultiYearChartSA(@RequestParam String majorName, @RequestParam String graduationYears){
        log.info("22专业单选-年份多选_图表");
        SystemSA22ChartVO vo = statisticAnalysisService.oneMajorMultiYearChart(majorName, graduationYears);
        return Result.success(vo);
    }

//    32老师单选-年份多选
//    32-1概览情况
    @Operation(summary = "18老师单选-年份多选_概览")
    @GetMapping("/one-teacher-multi-year-view")
    public Result<SystemSA32ViewVO> oneTeacherMultiYearViewSA(@RequestParam String teacherAccount,@RequestParam String graduationYears){
        log.info("32老师单选-年份多选_概览");
        SystemSA32ViewVO list= statisticAnalysisService.oneTeacherMultiYearView(teacherAccount, graduationYears);
        if(list.getPassCount()==0|| list.getYearCount()==0){
            return Result.error("符合条件的数据为空，请重新选择查询条件");
        }
        return Result.success(list);
    }
//    32-2图表区域
    @Operation(summary = "19老师单选-年份多选_图表")
    @GetMapping("/one-teacher-multi-year-chart")
    public Result<SystemSA32ChartVO> oneTeacherMultiYearChartSA(@RequestParam String teacherAccount,@RequestParam String  graduationYears){
        log.info("32老师单选-年份多选_图表");
        SystemSA32ChartVO vo = statisticAnalysisService.oneTeacherMultiYearChart(teacherAccount, graduationYears);
        return Result.success(vo);
    }
}
